package org.lq.his.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.lq.his.pojo.DoctorRankClass;
import org.lq.his.pojo.Myo;
import org.lq.his.pojo.Prescribe;
import org.lq.his.service.prescribeService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/prescribe")
public class prescribeController {
	@Resource
	private prescribeService prescribeService;

	public void setPrescribeService(prescribeService prescribeService) {
		this.prescribeService = prescribeService;
	}
	@RequestMapping("/prescribeIndex")
	public String prescribeIndex()throws Exception{
		return "prescribe/prescribeIndex";
	}
	@RequestMapping(value="/prescribeForm",method=RequestMethod.GET)
	public String prescribeForm()throws Exception{
		return "prescribe/prescribeForm";
	}
	@RequestMapping("/list") 
	@ResponseBody
	public Map<String, Object> list(@RequestParam(defaultValue="1")Integer  page,@RequestParam(defaultValue="5")Integer  rows,@RequestParam(defaultValue="id") String sort,@RequestParam(defaultValue="asc") String order, Prescribe condition) throws Exception{
		
		Map<String, Object> map = new HashMap<>();
		int start = (page - 1)*rows;
		List<Prescribe> list = prescribeService.getListByCondition(start, rows, condition, sort,order);
		
		int total = prescribeService.getCountByCondition(condition);
		
		map.put("total", total);
		map.put("rows", list);
		
		return map;
	}
	@RequestMapping(value="/add",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> add(Prescribe prescribe)throws Exception{
		Map<String, Object> map = new HashMap<>();
		prescribeService.add(prescribe);
		map.put("result", true);
		return map;
	}
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> edit(Prescribe prescribe)throws Exception{
		Map<String, Object> map = new HashMap<>();
		prescribeService.update(prescribe);
		
		map.put("result", true);
		
		return map;
	}
	
	@RequestMapping("/view")
	@ResponseBody
	public Prescribe view(Integer id)throws Exception{
		return prescribeService.getById(id);
	}
	
	@RequestMapping("/deletepre")
	@ResponseBody
	public Map<String, Object> deleteMyo(Integer[] ids)throws Exception{
		prescribeService.deletePre(ids);
		Map<String, Object> map= new HashMap<>();
		map.put("result", true);
		return map;
	}
	@RequestMapping("/allpre")
	public List<Prescribe> getAll()throws Exception{
		return prescribeService.getAll();
	}
	
	@RequestMapping("/getListByConditionWeiNa")
	@ResponseBody
	public List<Prescribe> getListByConditionWeiNa(@RequestParam(defaultValue="1")Integer  page,@RequestParam(defaultValue="5")Integer  rows,@RequestParam(defaultValue="id") String sort,@RequestParam(defaultValue="asc") String order, Prescribe condition) throws Exception{
		//设置查询条件 是否开药为0,未发药的
		condition.setDispensing(0);
		Map<String, Object> map = new HashMap<>();
		int start = (page - 1)*rows;
		List<Prescribe> list = prescribeService.getListByCondition(start, rows, condition, sort,order);
		
		int total = prescribeService.getCountByCondition(condition);
		
		map.put("total", total);
		map.put("rows", list);
		
		return prescribeService.getListByCondition(start, page, condition, sort, order);
		
	}

}
